import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;


public class SocketServer
{
	static public final int portNumber = 3657;
	
	
	public static void main(String args[])
	{
		try
		{
			new SocketServer();
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	SocketServer() throws IOException
	{	
		ServerSocket server = new ServerSocket(portNumber);
		while(true)
		{
			System.out.println("Istemci bekleniyor..");
			Socket sock = server.accept();
			System.out.println("Istemci saglandi.");
			
			ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());
			
			Date d = new Date();
			server.getInetAddress();
			out.writeObject("Merhaba. " +
					"Bugun: " 		+ String.format("%td/%tm/%tY",d,d,d) + "\n" +
					"Saat: " 		+ String.format("%tT", d) + "\n" +
					"Ben: " 		+ InetAddress.getLocalHost() + "\n" +
					"Sen: " 		+ sock.getInetAddress() + "\n" +
					"Local port: " 	+ sock.getLocalPort() + "\n" +
					"Remote port: " + sock.getPort() + "\n" +
					"Bye!");
			
			System.out.println("Mesaj gonderildi.");
			sock.close();
		}
	}
	
}

